package com.zzyl.config;

import com.aliyun.iot20180120.Client;
import com.aliyun.teaopenapi.models.Config;
import com.zzyl.properties.AliyunIotProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AliyunIotConfig {

    @Autowired
    AliyunIotProperties aliyunIotProperties;

    /**
     * 自动配置 Client 对象
     *
     * @return
     * @throws Exception
     */
    @Bean
    public Client client() throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(aliyunIotProperties.getAccessKeyId())
                // 您的AccessKey Secret
                .setAccessKeySecret(aliyunIotProperties.getAccessKeySecret());
        //设置区域
        config.regionId = aliyunIotProperties.getRegionId();

        Client client = new Client(config);

        return client;
    }
}